package com.company.socks5;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class SocksProxyFrameDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        while (in.readableBytes() >= 10) {
            int packetLength = in.getIntLE(in.readerIndex());
            if (in.readableBytes() < packetLength) {
                return; // 等待更多数据
            }
            out.add(in.readRetainedSlice(packetLength));
        }
    }
}